package com.sky.mapper.admin;

import com.github.pagehelper.Page;
import com.sky.aop.AutoFill;
import com.sky.dto.DishPageQueryDTO;
import com.sky.enumeration.OperationType;
import com.sky.pojo.Dish;
import com.sky.vo.DishVO;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * @Description DishMapper
 * @Author lyh
 * @Date 2024-09-20
 */
@Mapper
public interface DishMapper {
    /**
     * 查询改分类id在菜品出出现的次数
     * @param categoryId
     * @return
     */
    @Select("select count(*) from dish where category_id=#{categoryId}")
    Integer countByCategoryId(Integer categoryId);
    @Insert("insert into dish (name, category_id, price, image, description,status, create_time, update_time, create_user, update_user, make_time)\n" +
            "values (#{name},#{categoryId},#{price},#{image},#{description},#{status},#{createTime},#{updateTime},#{createUser},#{updateUser},#{makeTime}) ")
    @Options(useGeneratedKeys = true,keyProperty = "id")
    @AutoFill(value= OperationType.INSERT)
    void save(Dish dish);

    /**
     * 分页查询
     * @param dto
     * @return
     */
    Page<DishVO> pageQuery(DishPageQueryDTO dto);

    /**
     * 批量删除菜品
     * @param ids
     */
    void delete(@Param("ids") List<Long> ids);

    /**
     * 统计起售状态的商品个数
     * @param ids
     * @param status
     * @return
     */
    Integer countByStatus(@Param("ids") List<Long> ids, @Param("status") Integer status);

    /**
     *根据id获取菜品及风味
     * @param dishId
     * @return
     */
    DishVO getById(Long dishId);

    /**
     *修改菜品
     * @param dish
     */
    @AutoFill(value= OperationType.UPDATE)
    void update(Dish dish);
    @Update("update dish set status=#{status} where id=#{id}")
    void updateStatus(@Param("status") Integer status,@Param("id") Long id);

    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id=#{categoryId} and status=#{status}")
    List<Dish> list(@Param("categoryId") Long categoryId,@Param("status") Integer status);

    List<DishVO> list1(@Param("categoryId") Long categoryId,@Param("status") Integer status);
    @Select("select count(*) from dish where status=#{status} ")
    Integer countStatus(Integer status);
}
